package de.grosjohann.android.feuerwehr.domain;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import de.grosjohann.android.feuerwehr.R;
import de.grosjohann.android.feuerwehr.type.FireIndexType;
import de.grosjohann.android.feuerwehr.util.ContextUtil;

public class FireIndex
  extends AbstractWarning<FireIndexType>
  implements Serializable {

  public FireIndex(JSONObject obj) throws JSONException {
    super(FireIndexType.valueOf(obj.getInt("level")));
  }

  @Override
  public String getMessage() {
    return ContextUtil.getContext().getString(R.string.lblFireIndex);
  }

  @Override
  public String getDetail() {
    return ContextUtil.getContext().getString(getLevel().getResId());
  }

  @Override
  public String getEnd() {
    return null;
  }

  @Override
  public String toString() {
    return getLevel().name();
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((getLevel() == null) ? 0 : getLevel().hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    FireIndex other = (FireIndex) obj;
    if (getLevel() != other.getLevel())
      return false;
    return true;
  }
}
